package cn.qqtheme.framework.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.qqtheme.framework.icons.FilePickerIcon;
import cn.qqtheme.framework.util.ConvertUtils;
import java.util.Collections;
import java.util.LinkedList;
import net.lingala.zip4j.util.InternalZipConstants;

/* loaded from: classes.dex */
public class PathAdapter extends BaseAdapter {
    private static final String ROOT_HINT = "ROOT";
    private LinkedList<String> paths = new LinkedList<>();
    private Drawable arrowIcon = null;

    @Override // android.widget.Adapter
    public long getItemId(int i) {
        return i;
    }

    public void setArrowIcon(Drawable drawable) {
        this.arrowIcon = drawable;
    }

    public void updatePath(String str) {
        if (this.arrowIcon == null) {
            this.arrowIcon = ConvertUtils.toDrawable(FilePickerIcon.getARROW());
        }
        this.paths.clear();
        if (!str.equals(InternalZipConstants.ZIP_FILE_SEPARATOR)) {
            Collections.addAll(this.paths, str.substring(str.indexOf(InternalZipConstants.ZIP_FILE_SEPARATOR) + 1).split(InternalZipConstants.ZIP_FILE_SEPARATOR));
        }
        this.paths.addFirst(ROOT_HINT);
        notifyDataSetChanged();
    }

    @Override // android.widget.Adapter
    public int getCount() {
        return this.paths.size();
    }

    @Override // android.widget.Adapter
    public String getItem(int i) {
        if (i == 0) {
            return InternalZipConstants.ZIP_FILE_SEPARATOR;
        }
        String str = InternalZipConstants.ZIP_FILE_SEPARATOR;
        for (int i2 = 1; i2 <= i; i2++) {
            str = str + this.paths.get(i2) + InternalZipConstants.ZIP_FILE_SEPARATOR;
        }
        return str;
    }

    @Override // android.widget.Adapter
    public View getView(int i, View view, ViewGroup viewGroup) {
        LinearLayout linearLayout;
        ViewHolder viewHolder;
        Context context = viewGroup.getContext();
        if (view == null) {
            LinearLayout linearLayout2 = new LinearLayout(context);
            linearLayout2.setOrientation(0);
            linearLayout2.setGravity(16);
            if (viewGroup instanceof AbsListView) {
                linearLayout2.setLayoutParams(new AbsListView.LayoutParams(-1, -1));
            } else {
                linearLayout2.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
            }
            TextView textView = new TextView(context);
            textView.setLayoutParams(new LinearLayout.LayoutParams(-2, -1));
            textView.setGravity(8388627);
            int px = ConvertUtils.toPx(context, 5.0f);
            textView.setPadding(px, 0, px, 0);
            linearLayout2.addView(textView);
            ImageView imageView = new ImageView(context);
            imageView.setLayoutParams(new LinearLayout.LayoutParams(ConvertUtils.toPx(context, 20.0f), -1));
            linearLayout2.addView(imageView);
            viewHolder = new ViewHolder();
            viewHolder.textView = textView;
            viewHolder.imageView = imageView;
            linearLayout2.setTag(viewHolder);
            linearLayout = linearLayout2;
        } else {
            linearLayout = view;
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.textView.setText(this.paths.get(i));
        viewHolder.imageView.setImageDrawable(this.arrowIcon);
        return linearLayout;
    }

    public void recycleData() {
        Bitmap bitmap;
        this.paths.clear();
        Drawable drawable = this.arrowIcon;
        if (!(drawable instanceof BitmapDrawable) || (bitmap = ((BitmapDrawable) drawable).getBitmap()) == null || bitmap.isRecycled()) {
            return;
        }
        bitmap.recycle();
    }

    /* loaded from: classes.dex */
    private static class ViewHolder {
        ImageView imageView;
        TextView textView;

        private ViewHolder() {
        }
    }
}
